<template>
<!-- 商品审核 -->
  <div class="chonges">
    <el-tabs>
      <el-table :data="list" style="width: 100%">
        <el-table-column label="商品Id" prop="commodityId" width="150">
        </el-table-column>
        <el-table-column
          label="商品分类"
          width="100"
          prop="categories[0].desc"
        ></el-table-column>
        <el-table-column
          label="商品名称"
          width="120"
          prop="title"
        ></el-table-column>
        <el-table-column label="商品图片" width="120">
          <template v-slot="{ row }">
            <el-image :src="row.mainImages[0]"/>
          </template>
        </el-table-column>
        <el-table-column label="商品品牌" prop="attributes[0].value" width="120">
        </el-table-column>
        <el-table-column label="产地" prop="attributes[1].value" width="120">
        </el-table-column>
        <el-table-column label="商品规格" prop="specs[0].name" width="120">
        </el-table-column>
        <el-table-column label="平台售价" prop="specs[0].costPrice" width="120">
        </el-table-column>
        <el-table-column label="市场价" prop="specs[0].marketPrice" width="120">
        </el-table-column>
        <el-table-column label="成本价" prop="specs[0].platformPrice" width="120">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
          <template v-slot="{ row }">
             <el-button type="text" size="small" @click="heacteng(row,a)"
              >查看详细</el-button
            >
            <el-button type="text" size="small" @click="heact(row)"
              >同意</el-button
            >
            <el-button type="text" size="small" @click="hdown(row)"
              >拒绝</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="liyongxin"
        :current-page="q.index"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-tabs>
  </div>
</template>

<script>
import { gitlogin, transit, reject } from "@/api/login";

export default {
  data() {
    return {
      a:'1',
      list: [],
      q: {
        index: 1,
        size: 10,
      },
    };
  },
  created() {
    this.loaconst();
 
  },
  methods: {
    async loaconst() {
      const res = await gitlogin(this.q);
  
      this.list = res.data.data;
      

    },
    // 审核通过
    heact(row) {
      
      this.$confirm("您确定要通过么？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const params = new URLSearchParams();
        params.append("commodityId", row.commodityId);
        const res = await transit(params);
        row.rejectDesc = ''
        this.loaconst();
        if (res.code !== 200) return;
        this.$message.success(res.msg);
      });
    },
    // 审核不通过
    hdown(row) {
      row.rejectDesc = ''
      this.$prompt("请输入拒绝理由", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal:false,
        inputPattern:/^.+$/,
        inputErrorMessage: '请输入拒绝理由'
      })
        .then(async ({ value }) => {
          const param = new URLSearchParams();
          param.append("rejectDesc", row.rejectDesc + value);
          param.append("commodityId", row.commodityId);

          const res = await reject(param);
          this.loaconst();
          if (res.code !== 200) return;
          this.$message.error(res.msg);
          this.$message.success(res.msg);
        })
        .catch(() => {
          this.$message({ type: "info", message: "取消输入" });
        });
    },

    // 分页
    handleCurrentChange(index) {
      this.q.index = index;
      this.loaconst();
    },
    handleSizeChange(size) {
      this.q.size = size;
      this.loaconst();
    },
    // 查看详细
      heacteng(row,a) {
      // console.log(row);
      this.$router.push({
        path: "/home/acctcpeol",
        query: { row,a },
      });
    },
  },
};
</script>

<style scoped>
.chonges {
  background-color: #fff;
}
.el-image {
  width: 35px;
  height: 35px;
  margin-left: 10px;
}
</style>
